import { EmployeesApi } from '@/api/Employees.api.js'
import { BillApi } from '@/api/Bill.api.js'
import { SysWelfarePercentEmployeeConfigApi } from '@/api/SysWelfarePercentEmployeeConfig.api.js'
import { SysWelfarePercentConfigDetailApi } from '@/api/SysWelfarePercentConfigDetail.api.js'
import { SysWelfarePercentNoConfigApi } from '@/api/SysWelfarePercentNoConfig.api.js'
import { SysWelfarePercentAreaConfigApi } from '@/api/SysWelfarePercentAreaConfig.api.js'
import { FormShebaoFilter, FormShebaoFilterItem, FormShebaoFilterOnlyViewItem, FormShebaoTitle, FormShebao, FormShebaoItem } from './EBformData.js'
import { shebaoThead, shebaojiluThead, shebaoListThead } from './EBtableHead.js'
import _cloneDeep from 'clone-deep'
import { Common } from '@/utils/common.js'
import { EBbase } from './EBbase.js'

export default {
  props: {
    serviceFeeType: {
      type: Number,
      default: 0
    },
    // isOnlyView: {
    //   type: Boolean,
    //   default: false
    // },
    isInsuranceInfoSet: {
      type: Boolean,
      default: false
    }
  },

  computed: {
    setFormShebaoFilterItem () {
      if (this.isDataOperator && this.isBatch) {
        this.formShebaoFilterItem.map((item, index) => {
          if (['insuredTime', 'payMonth', 'description'].indexOf(item.model) !== -1) {
            item.isShow = false
          }
        })
      } else {
      }
      return this.formShebaoFilterItem
    }
  },

  data () {
    return {
      isOnlyView: true,
      canEditor: null,
      isCreateNew: false,
      selectedEmployeeId: [], // 选中的员工ID
      companyId: '', // 公司ID
      companyName: '', // 公司名称
      insuranceId: '', // 保险ID
      formShebaoFilter: _cloneDeep(FormShebaoFilter),
      formShebaoFilterItem: _cloneDeep(FormShebaoFilterItem),
      formShebaoFilterOnlyViewItem: _cloneDeep(FormShebaoFilterOnlyViewItem),
      formShebaoTitle: _cloneDeep(FormShebaoTitle),
      formShebao: _cloneDeep(FormShebao),
      formShebaoItem: _cloneDeep(FormShebaoItem),
      datePickerDefault: new Date(),
      rules: {},
      SecurityId: '', // 社保方案ID
      arrListDown: {
        securitys: [],
        securitysPlay1: []
      },
      shebaoThead: _cloneDeep(shebaoThead),
      shebaojiluThead: _cloneDeep(shebaojiluThead),
      shebaoListThead: _cloneDeep(shebaoListThead),
      tableData: [],
      recordTableData: [],
      tableComone: {
        pageIndex: 1, // 页码
        totalRows: 0, // 总条数
        pageSize: 10 // 当前页面展示条数
      },
      selectedId: '',
      configInfo: {},
      isNext: false,
      dateOptions: {
        disabledDate (date) {
          const disabledDay = date.getDate()
          const month = date.getMonth()
          const nowMonth = (new Date()).getMonth()
          if (month === nowMonth) {

          } else {
            return disabledDay !== 1
          }
        }
      },
      isCanSave: true,
      allInsuranceNum: '',
      fiveInsuranceNum: '',
      declareSalary: '',
      employeeBasicInfo: null,
      isBatch: false,
      isBatchOut: true,
      isEdit: false, // 是否可以编辑
      isCreateRecord: false, // 是否新增记录
      tableListData: [],
      moreShebao: [],
      checkEmployeeNum: null,
      isFromRoster: null,
      isDataOperator: null // 是否是管理员身份
    }
  },

  mounted () {
    this.employeeId = this.$route.query.employeeId // 员工ID
    this.companyId = this.$route.query.companyId // 公司ID
    this.companyName = this.$route.query.companyName // 公司名称
    this.isFromRoster = this.$route.query.isFromRoster // 是否从员工管理页面过来
    this.canEditor = !!(this.$route.query.checkEmployeeNum || this.$route.query.isCreateNew || this.$route.query.isBatch)
    this.isOnlyView = this.$route.query.isOnlyView
    this.isCreateNew = !!this.$route.query.isCreateNew
    this.checkEmployeeNum = this.$route.query.checkEmployeeNum
    this.selectedEmployeeId = JSON.parse(localStorage.getItem('selectedEmployeeId')) // 选中的员工
    this.employeeBasicInfo = JSON.parse(localStorage.getItem('employeeBasicInfo')) // 当前员工基本信息
    this.isDataOperator = JSON.parse(localStorage.getItem('isDataOperator')) // 是否是管理员身份

    this.isBatch = this.$route.query.isBatch // 是否批量
    this.isBatchOut = this.$route.query.isBatchOut // 是否批量
    console.log(this.isBatchOut,"___________isBatchOut__________")
    // this.getConfig()
    if (!this.canEditor && this.employeeBasicInfo) {
      this.employeeInsureDetails()
      // this.getConfigList()
    }

    if (this.isOnlyView) {
      this.getConfigList()
    } else {
      this.getConfig()
    }

    this.getList()
  },

  methods: {
    // 监听所有调用的方法
    listenCall (methodsWords, ...values) {
      console.log(methodsWords, ...values,'listenCall')
      if(methodsWords == 'getPlanList'){
        let param = [...values]
        if (!param[0]) {
          return
        }
      }
      this[methodsWords](...values)
    },

    async handleSubmit (name) {
      var tempAmounts = []
      this.configInfo.details.map(item => {
        var aloneObg = { SecurityTypeCode: item.securityTypeCode }
        if (item.company) {
          aloneObg.CompanyBaseAmount = item.company.baseAmount
        }
        if (item.employee) {
          aloneObg.EmployeeBaseAmount = item.employee.baseAmount
        }
        tempAmounts.push(aloneObg)
      })
      console.log('tempAmounts: ', tempAmounts)

      var params = {
        id: this.insuranceId,
        securityType: 1, // 参保类型（1社会保险、2公积金）
        rangeGUID: this.formShebaoFilter.rangeGUID, // 社保编号
        employeeGUID: this.employeeId, // 员工ID
        securityGUID: this.formShebaoFilter.securityGUID, // 社保方案
        insuredTime: this.formShebaoFilter.insuredTime, // 参保时间
        description: this.formShebaoFilter.description, // 备注
        amounts: tempAmounts,
        declareSalary: this.formShebaoFilter.declareSalary
      }
      let res = await SysWelfarePercentEmployeeConfigApi.saveShebaoOrGongjijin(params)
      console.log('提交表单res: ', res)
      if (res.status === 200 && res.data.success) {
        this.$Message.success(res.data.message)
        this.isNext = true
        this.insuranceId = res.data.data
        this.isEdit = false
        this.getList()
        this.$emit('saveSuccess', res.data.data)
      } else {
        this.$Message.error({
          content: res.data.message,
          duration: 10,
          closable: true
        })
      }
    },

    async handleSubmitBatch (name) {
      var tempAmounts = []
      this.configInfo.details.map(item => {
        var aloneObg = { SecurityTypeCode: item.securityTypeCode }
        if (item.company) {
          aloneObg.CompanyBaseAmount = item.company.baseAmount
        }
        if (item.employee) {
          aloneObg.EmployeeBaseAmount = item.employee.baseAmount
        }
        tempAmounts.push(aloneObg)
      })
      console.log('tempAmounts: ', tempAmounts)
      console.log(this.formShebaoFilter,'??????????')
      var params = {
        securityType: 1, // 参保类型（1社会保险、2公积金）
        rangeGUID: this.formShebaoFilter.rangeGUIDs, // 社保编号
        employeeIdList: this.selectedEmployeeId, // 员工ID
        securityGUID: this.formShebaoFilter.rangeGUID, // 社保方案
        insuredTime: this.formShebaoFilter.insuredTime, // 参保时间
        description: this.formShebaoFilter.description, // 备注
        declareSalary: this.formShebaoFilter.declareSalary, // 申报工资
        amounts: tempAmounts
      }
      let res = await SysWelfarePercentEmployeeConfigApi.batchSaveShebaoOrGongjijin(params)
      console.log('提交表单res: ', res)
      if (res.status === 200 && res.data.success) {
        this.$Message.success(res.data.message)
        this.isNext = true
        this.$emit('saveSuccess', res.data.data)
        this.fiveInsuranceNum = ''
      } else {
        this.$Message.error({
          content: res.data.message,
          duration: 10,
          closable: true
        })
      }
    },

    // 上一步
    handlepageUp () {
      Common.pageUp(this, 3) // '社保'的上一页，是'员工参保信息'，这个不会变
    },

    // 下一步
    handlepageDown () {
      if ([12, 23].indexOf(this.serviceFeeType) !== -1) { // 参保种类选择了'社保+公积金' || '公积金+商保'
        Common.pageDown(this, 5) // 跳转到'公积金'页面
      } else if (this.serviceFeeType === 13) { // 参保种类选择了'社保+商保'
        Common.pageDown(this, 6) // 跳转到'商保'页面
      } else if (this.serviceFeeType === 1) {
        Common.pageDown(this, 7) // 跳转到'薪资'页面
      } else {
        Common.pageDown(this)
      }
    },

    // 表格选择操作
    handleOnSelectChange (value) {
      let arr = value.map((item) => {
        return item.id
      })
      this.selectedId = arr.join(',')
      console.log('列表勾选', this.selectedId)
    },

    // 修改
    handleModify () {
      this.isNext = true
      this.$emit('handleModify', 4)
    },

    // 输入补缴月数计算参保时间
    toCountDate (form, month) {
      EBbase.toCountDate(this.formShebaoFilter, month)
    },

    // 输入参保时间计算补缴月数
    toCountMonth (form, date) {
      EBbase.toCountMonth(this.formShebaoFilter, date)
    },

    // 返回员工花名册列表
    goEmployeeBookList () {
      this.$router.push({
        path: '/EmployeeBook',
        name: 'EmployeeBook',
        query: {
          companyId: this.companyId,
          companyName: this.companyName
        }
      })
    },

    // 根据ID获取员工参保基数配置信息
    async getConfig (id) {
      var params = {
        SecurityType: 1,
        CompanyGUID: this.companyId,
        EmployeeGUID: this.employeeId
      }
      if (id) {
        params.id = id
      }
      let res = await SysWelfarePercentEmployeeConfigApi.getConfig(params)
      if (res.status === 200 && res.data.success && res.data.data.config) {
        var result = res.data.data
        this.configInfo = result.config // 保险信息
        this.insuranceId = result.config.id // 保险id
        console.log('🚩🚩🚩', this.insuranceId)
        this.formShebaoFilter.insuredTime = result.config.add.declareDate // 参保时间
        this.formShebaoFilter.payMonth = result.config.payMonth // 补缴月份
        console.log('🌼🌼🌼 参保时间: ', this.formShebaoFilter.insuredTime)
        // EBbase.toCountMonth(this.formShebaoFilter, new Date(result.config.add.declareDate))
        // this.formShebaoFilter.securityGUID = result.config.securityGUID // 社保编号

        // 社保编号下拉框
        var tempSecuritys = []
        if (result.securitys) {
          result.securitys.map(item => {
            tempSecuritys.push({ label: item.text, value: item.value })
          })
        }
        this.arrListDown.securitys = tempSecuritys

        if (result.config.rangeGUID) {
          this.getPlanList(result.config.rangeGUID, 1, this.arrListDown)
        }

        this.formShebaoFilter.rangeGUID = result.config.rangeGUID // 社保编号
        this.formShebaoFilter.securityGUID = result.config.securityGUID // 社保方案
        this.formShebaoFilter.description = result.config.description // 备注
        // this.formShebaoFilter.declareSalary = result.config.declareSalary // 备注

        // 参保信息配置显示到表格-动态加载表格列
        console.log('开始放大招了！')
        var tempThead = []
        this.configInfo.details.map(item => {
          var strCompany = item.securityTypeCode + 'Company'
          var strEmployee = item.securityTypeCode + 'Employee'
          if (item.company) {
            tempThead.push({ title: item.securityTypeName + '(单位)', key: strCompany, minWidth: 150 })
          }
          if (item.employee) {
            tempThead.push({ title: item.securityTypeName + '(个人)', key: strEmployee, minWidth: 150 })
          }
        })
        console.log('tempThead: ', tempThead)
        this.shebaoThead = tempThead
        EBbase.parseConfigInfoIsOnlyView(this.configInfo, this.formShebaoFilter, this.tableData)

        Object.keys(this.tableData[1]).forEach(key => {
          this.tableData[1][key] = this.tableData[1][key] + '%'
        })
      }
    },

    // 根据员工ID和参保类型获取参保明细信息
    async getConfigList (id) {
      var params = {
        SecurityType: 1,
        CompanyGUID: this.companyId,
        EmployeeGUID: this.employeeId
      }
      if (id) {
        params.id = id
      }
      let res = await SysWelfarePercentConfigDetailApi.getList(params)
      console.log('🌼🌼🌼 🍃🍃🍃 res: ', res)
      if (res.status === 200 && res.data.success) {
        res.data.data.map(table => {
          table.parsingData = []
          EBbase.readAddModelValToTable(table.details, table.parsingData, 'baseAmount')
          EBbase.readAddModelValToTable(table.details, table.parsingData, 'percent')

          Object.keys(table.parsingData[1]).forEach(key => {
            table.parsingData[1][key] = table.parsingData[1][key] ? table.parsingData[1][key] + '%' : ''
          })
        })
        this.moreShebao = res.data.data
        console.log('❌❌❌ this.moreShebao: ', this.moreShebao)
      }
    },

    // 根据ID获取员工参保基数配置信息(批量)
    async getBatchConfig () {
      var params = {
        SecurityType: 1,
        EmployeeIdList: this.selectedEmployeeId
      }
      let res = await SysWelfarePercentEmployeeConfigApi.getBatchConfig(params)
      if (res.status === 200 && res.data.success && res.data.data.config) {
        var result = res.data.data
        this.configInfo = result.config // 保险信息
        this.insuranceId = result.config.id // 保险id
        var tempSecuritys = result.securitys // 社保编号下拉框
        if (result.securitys) {
          result.securitys.map(item => {
            this.arrListDown.securitys.push({ label: item.securityNO, value: item.id })
            this.arrListDown.securitysPlay1.push({ label: item.planName, value: item.planGUID })
          })
        }

        // if (result.config.rangeGUID) {
        //   this.getPlanList(result.config.rangeGUID, 1, this.arrListDown)
        // }
        this.formShebaoFilter.rangeGUIDs =  result.securitys[0].rangeGUID
        this.formShebaoFilter.rangeGUID = result.securitys[0].id // 社保编号
        this.formShebaoFilter.securityGUID = result.securitys[0].planGUID // 社保方案
        this.formShebaoFilter.description = result.config.description // 备注
        this.getAddModel2(this.formShebaoFilter.rangeGUID)
      } else {
        console.log(res,'error')
        this.$Message.error(JSON.parse(res.data).message)
      }
    },

    changeRangeGUID (e) {
      this.fiveInsuranceNum =''
      if (this.isBatchOut) {
        this.getAddModel2(e)
      } else {
        this.getPlanList(e, 1, this.arrListDown)
        console.log(e,'getPlanList-changeRangeGUID')
      }
    },

    changeSecurityGUID (e) {

    },

    // 获取社保编号
    async getAddModel (securityType, securityGUID, companyId) {
      var params = {
        SecurityType: securityType,
        SecurityGUID: securityGUID,
        CompanyGUID: companyId
      }
      let res = await SysWelfarePercentEmployeeConfigApi.getAddModel(params)
      console.log('获取社保编号res: ', res)
    },

    // 获取社保方案
    async getPlanList (securityGUID, securityType, arr) {
      console.log(securityGUID, securityType, arr,'getPlanList  ')
      this.arrListDown.securitysPlay1 = []
      this.formShebaoFilter.securityGUID = ''
      var tempArr = []
      var params = {
        CompanyGUID: this.companyId,
        SecurityType: securityType,
        SecurityNO: securityGUID
      }
      let res = await SysWelfarePercentNoConfigApi.getPlanList(params)
      console.log('获取社保方案res: ', res)
      if (res.status === 200 && res.data.success) {
        res.data.data.map(item => {
          tempArr.push({ label: item.text, value: item.value })
        })
      } else {
        tempArr = []
      }
      this.arrListDown.securitysPlay1 = tempArr
      console.log(this.arrListDown,'this.arrListDown')
      console.log(tempArr,'this.tempArr')
      this.allInsuranceNum = ''
      this.fiveInsuranceNum = ''
      this.formShebaoFilter.securityGUID = this.formShebaoFilter.securityGUID?this.formShebaoFilter.securityGUID:tempArr[0].value
      // this.formShebaoFilter.declareSalary = ''

      console.log('💧 是否新增一条记录：this.isCreateRecord: ', this.isCreateRecord)
      // 选择社保编号后，默认社保方案为第一条
      // if (!this.formShebaoFilter.securityGUID && tempArr.length > 0 && !this.checkEmployeeNum) {
      console.log(this.formShebaoFilter.securityGUID, tempArr.length > 0 , (this.isCreateRecord || this.$route.query.isBatch))
      if (this.formShebaoFilter.securityGUID!=null && tempArr.length > 0 && (this.isCreateRecord || this.$route.query.isBatch)) {
        this.formShebaoFilter.securityGUID = tempArr[0].value
        this.getAddModel2(tempArr[0].value)
      }
    },

    // 拿到社保方案后获取的社保参数配置
    async getAddModel2 (selectId) {
      if (selectId) {
        console.log(this.isBatchOut,"getAddModel2---isBatchOut")
        if(!this.isBatchOut){
          var params = {
            SecurityType: 1,
            CompanyGUID: this.companyId,
            SecurityGUID: selectId,
          }
          let res = await SysWelfarePercentEmployeeConfigApi.getAddModel(params)
          console.log('🈲 getAddModel2 res: ', res)
          if (res.status === 200 && res.data.success) {
            var result = res.data.data
            this.configInfo = result.config // 保险信息
            
          } else {
            this.$Message.error({
              content: res.data.message,
              duration: 10,
              closable: true
            })
          }
          this.formShebaoFilter.declareSalary = ''
        } else {
          var params = {
            SecurityType: 1,
            CompanyGUID: this.companyId,
            SecurityGUID: selectId,
            EmployeeIdList: this.selectedEmployeeId
          }
          // let res = await SysWelfarePercentEmployeeConfigApi.getAddModel(params)
          let res = await SysWelfarePercentEmployeeConfigApi.getBatchConfig(params)
          console.log('🈲 getAddModel3 res: ', res)
          if (res.status === 200 && res.data.success) {
            var result = res.data.data
            this.configInfo = result.config // 保险信息
            console.log('arrlist',this.arrListDown)
            for (let i in result.securitys) {
              if(result.securitys[i].id == selectId) {
                this.formShebaoFilter.rangeGUID = result.securitys[i].id
                this.formShebaoFilter.rangeGUIDs =  result.securitys[i].rangeGUID
                break
              }
            }
            this.arrListDown.securitysPlay1 = [{label:result.securitys[0].planName,value:result.securitys[0].planGUID}]
          } else {
            this.$Message.error({
              content: res.data.message,
              duration: 10,
              closable: true
            })
          }
          this.formShebaoFilter.declareSalary = ''
        }
        
      }
    },

    // 默认基数改变时，重新计算缴纳金额
    async baseAmountOnBlur (baseAmount, precision, percent, section, rowIndex) {
      this.formShebaoFilter.declareSalary = '' // 申报工资清零
      var params = {
        money: baseAmount, // 金额
        precision: precision, // 精度
        percent: percent // 比例
      }
      let res = await SysWelfarePercentAreaConfigApi.getTotalAmount(params)
      if (res.status === 200 && res.data.success) {
        console.log('计算单条缴纳金额res: ', res)
        if (res.status === 200 && res.data.success) {
          this.configInfo.details[rowIndex][section].totalAmount = res.data.data
        }
      }
    },

    // 所有险种输入框失去焦点时触发
    async allInsuranceOnBlue () {
      this.formShebaoFilter.declareSalary = '' // 申报工资清零
      var tempArr = []
      this.configInfo.details.map(item => {
        if (item.company) {
          item.company.baseAmount = this.allInsuranceNum
          tempArr.push({
            money: item.company.baseAmount, // 金额
            precision: item.company.precision, // 精度
            percent: item.company.percent, // 比例
            securityTypeCode: item.securityTypeCode,
            isCompany: true
          })
        }
        if (item.employee) {
          item.employee.baseAmount = this.allInsuranceNum
          tempArr.push({
            money: item.employee.baseAmount, // 金额
            precision: item.employee.precision, // 精度
            percent: item.employee.percent, // 比例
            securityTypeCode: item.securityTypeCode,
            isCompany: false
          })
        }
      })
      console.log('tempArr: ', tempArr)

      let res = await SysWelfarePercentAreaConfigApi.getSecurityTotalAmountList({ Details: tempArr })
      console.log('所有险种输入框失去焦点时触发: ', res)
      if (res.status === 200 && res.data.success) {
        var result = res.data.data
        result.map(item => {
          if (item.isCompany) {
            this.formShebao[item.securityTypeCode].Company.totalAmount = item.totalAmount
          } else {
            this.formShebao[item.securityTypeCode].Employee.totalAmount = item.totalAmount
          }
        })
        Object.keys(this.formShebao).forEach(key => {
          this.configInfo.details.map(item => {
            if (item.securityTypeCode === key) {
              if (item.company) {
                item.company.totalAmount = this.formShebao[key].Company.totalAmount
              }
              if (item.employee) {
                item.employee.totalAmount = this.formShebao[key].Employee.totalAmount
              }
              // item.employee.totalAmount = this.formShebao[key].Employee.totalAmount
            }
          })
        })
      }
    },

    // 五险输入框失去焦点时触发
    async fiveInsuranceOnBlue () {
      this.formShebaoFilter.declareSalary = '' // 申报工资清零
      var tempArr = []
      var insuranceArr = ['Pension', 'MedicalCare', 'Unemployment', 'InjuryOnTheJob', 'Birth']
      console.log('🌼', this.configInfo.details)
      this.configInfo.details.map(item => {
        if (insuranceArr.indexOf(item.securityTypeCode) !== -1) {
          if (item.company) {
            item.company.baseAmount = this.fiveInsuranceNum
            tempArr.push({
              money: item.company.baseAmount, // 金额
              precision: item.company.precision, // 精度
              percent: item.company.percent, // 比例
              securityTypeCode: item.securityTypeCode,
              isCompany: true
            })
          }
          if (item.employee) {
            item.employee.baseAmount = this.fiveInsuranceNum
            tempArr.push({
              money: item.employee.baseAmount, // 金额
              precision: item.employee.precision, // 精度
              percent: item.employee.percent, // 比例
              securityTypeCode: item.securityTypeCode,
              isCompany: false
            })
          }
        } else {
          if (item.company) {
            // item.company.baseAmount = this.fiveInsuranceNum
            tempArr.push({
              money: item.company.baseAmount, // 金额
              precision: item.company.precision, // 精度
              percent: item.company.percent, // 比例
              securityTypeCode: item.securityTypeCode,
              isCompany: true
            })
          }
          if (item.employee) {
            // item.employee.baseAmount = this.fiveInsuranceNum
            tempArr.push({
              money: item.employee.baseAmount, // 金额
              precision: item.employee.precision, // 精度
              percent: item.employee.percent, // 比例
              securityTypeCode: item.securityTypeCode,
              isCompany: false
            })
          }
        }
      })
      console.log('🌼 tempArr: ', tempArr)

      let res = await SysWelfarePercentAreaConfigApi.getSecurityTotalAmountList({ Details: tempArr })
      console.log('所有险种输入框失去焦点时触发: ', res)
      if (res.status === 200 && res.data.success) {
        var result = res.data.data
        result.map(item => {
          if (item.isCompany) {
            this.formShebao[item.securityTypeCode].Company.totalAmount = item.totalAmount
          } else {
            this.formShebao[item.securityTypeCode].Employee.totalAmount = item.totalAmount
          }
        })
        Object.keys(this.formShebao).forEach(key => {
          this.configInfo.details.map(item => {
            if (item.securityTypeCode === key) {
              if (item.company) {
                item.company.totalAmount = this.formShebao[key].Company.totalAmount
              }
              if (item.employee) {
                item.employee.totalAmount = this.formShebao[key].Employee.totalAmount
              }
              // item.employee.totalAmount = this.formShebao[key].Employee.totalAmount
            }
          })
        })
      }
    },

    // 搜索
    searchFn () {
      this.tableComone.pageIndex = 1
      this.query()
    },

    /**
     * 分页页码变动
     * @param {Number} val pageIndex
     */
    onChangePage (val) {
      this.tableComone.pageIndex = val
      this.query()
    },
    /**
     * 分页页码变动
     * @param {Number} val pageSize
     */
    onpageSizeChange (val) {
      this.tableComone.pageIndex = 1
      this.tableComone.pageSize = val
      this.query()
    },

    // 获取社保记录
    async employeeInsureDetails (selectId) {
      var params = {
        CustomerId: this.companyId,
        EmployeeId: this.employeeId,
        Category: 1, // 1-社保，2-公积金，4-商保
        IdCardType: this.employeeBasicInfo.idType,
        IdCardNo: this.employeeBasicInfo.idCardNo,
        HasPaging: true,
        PageIndex: this.tableComone.pageIndex,
        PageSize: this.tableComone.pageSize
      }
      // var params = {
      //   CustomerId: '946FB851-F1AC-E911-80BF-509A4C9F0611',
      //   EmployeeId: '30B85CB0-F1AC-E911-80BF-509A4C9F0611',
      //   Category: 1, // 1-社保，2-公积金，4-商保
      //   IdCardType: 0,
      //   IdCardNo: '431121199012033644',
      //   HasPaging: true,
      //   PageIndex: 1,
      //   PageSize: 10,
      // }
      let res = await BillApi.employeeInsureDetails(params)
      console.log('获取社保记录res: ', res)
      if (res.status === 200 && res.data.success) {
        this.recordTableData = res.data.data
        this.tableComone.totalRows = res.data.totalRows
        this.recordTableData.map(row => {
          row.insureItems.map(item => { // 循环解析insureItems里面的companyFee、employeeFee值并赋到相应的key
            var sumStr = ''
            if (item.companyFee) {
              Object.keys(item.companyFee).forEach(key => {
                sumStr = item.category + 'companyFee' + key
                row[sumStr] = item.companyFee[key]
              })
            }

            if (item.employeeFee) {
              Object.keys(item.employeeFee).forEach(key => {
                sumStr = item.category + 'employeeFee' + key
                row[sumStr] = item.employeeFee[key]
              })
            }
          })
        })
        console.log('🐟 this.recordTableData: ', this.recordTableData)
      }
    },

    // 申报工资
    async toDeclare () {
      var tempArr = []
      console.log('🌼 this.FormShebaoFilter.declareSalary: ', this.formShebaoFilter.declareSalary)
      console.log('🌼 this.configInfo.details: ', this.configInfo.details)
      this.configInfo.details.map(item => {
        if (item.company) {
          var max = item.company.maxAmount
          var min = item.company.minAmount
          if (this.formShebaoFilter.declareSalary < min) {
            item.company.baseAmount = min
          } else if (this.formShebaoFilter.declareSalary > max) {
            item.company.baseAmount = max
          } else {
            item.company.baseAmount = this.formShebaoFilter.declareSalary
          }

          tempArr.push({
            money: item.company.baseAmount, // 金额
            precision: item.company.precision, // 精度
            percent: item.company.percent, // 比例
            securityTypeCode: item.securityTypeCode,
            isCompany: true
          })
        }
        if (item.employee) {
          var max = item.employee.maxAmount
          var min = item.employee.minAmount
          if (this.formShebaoFilter.declareSalary < min) {
            item.employee.baseAmount = min
          } else if (this.formShebaoFilter.declareSalary > max) {
            item.employee.baseAmount = max
          } else {
            item.employee.baseAmount = this.formShebaoFilter.declareSalary
          }

          tempArr.push({
            money: item.employee.baseAmount, // 金额
            precision: item.employee.precision, // 精度
            percent: item.employee.percent, // 比例
            securityTypeCode: item.securityTypeCode,
            isCompany: false
          })
        }
      })
      console.log('🌼 tempArr: ', tempArr)

      let res = await SysWelfarePercentAreaConfigApi.getSecurityTotalAmountList({ Details: tempArr })
      console.log('所有险种输入框失去焦点时触发: ', res)
      if (res.status === 200 && res.data.success) {
        var result = res.data.data
        result.map(item => {
          if (item.isCompany) {
            this.formShebao[item.securityTypeCode].Company.totalAmount = item.totalAmount
          } else {
            this.formShebao[item.securityTypeCode].Employee.totalAmount = item.totalAmount
          }
        })
        Object.keys(this.formShebao).forEach(key => {
          this.configInfo.details.map(item => {
            if (item.securityTypeCode === key) {
              if (item.company) {
                item.company.totalAmount = this.formShebao[key].Company.totalAmount
              }
              if (item.employee) {
                item.employee.totalAmount = this.formShebao[key].Employee.totalAmount
              }
              // item.employee.totalAmount = this.formShebao[key].Employee.totalAmount
            }
          })
        })
      }
    },

    // 修改
    handleModify () {
      this.$emit('handleModify', 6)
    },

    // 修改当前条
    handleEditRow (row) {
      console.log('社保修改当前条row: ', row)
      this.isEdit = true
      this.isCreateRecord = false
      for (var item in row) {
        this.formShebaoFilter[item] = row[item]
      }
      this.getConfig(row.id)
    },

    // 删除员工社保信息(单个)-确认删除
    async handleSureDelete (id) {
      let res = await SysWelfarePercentEmployeeConfigApi.delete({ id: id })
      if (res.data.success) {
        this.$Message.success(res.data.message)
        // if (this.$route.query.isBatch) {
        //   this.queryBatch()
        // } else {
        //   this.query()
        // }
        this.getList()
      } else {
        this.$Message.error({
          content: res.data.message,
          duration: 10,
          closable: true
        })
      }
    },

    // 删除员工社保信息(批量)-确认删除
    async handleSureBatchDelete (securityGUID) {
      // var paramObj = {
      //   SecurityGUID: securityGUID,
      //   EmployeeIdList: this.selectedEmployeeId
      // }
      // console.log('🌙', paramObj)
      // let res = await SysWelfarePercentEmployeeCommercialConfigApi.batchDelete(paramObj)
      // if (res.data.success) {
      //   this.$Message.success(res.data.message)
      //   if (this.$route.query.isBatch) {
      //     this.queryBatch()
      //   } else {
      //     this.query()
      //   }
      // } else {
      //   
      //   this.$Message.error({
      //     content: res.data.message,
      //     // duration: 0,
      //     closable: true
      //   })
      // }
    },

    // 新增社保
    handleCreat () {
      this.insuranceId = ''
      Object.keys(this.formShebaoFilter).forEach(key => {
        if (key !== 'insuredTime') {
          this.formShebaoFilter[key] = '' // 表单内容置空
        }
      })
      this.formShebaoFilter.insuredTime = new Date()
      this.isEdit = true
      this.isCreateRecord = true
    },

    // 新增社保-批量
    handleBatchCreat () {
      this.insuranceId = ''
      Object.keys(this.formShebaoFilter).forEach(key => {
        if (key !== 'id' && key !== 'insuredTime') {
          this.formShangbaoFilter[key] = '' // 表单内容置空
        }
      })

      this.formShangbaoFilter.employeeIdList = this.selectedEmployeeId
      this.isEdit = true
    },

    // 根据员工ID和参保类型获取参保明细信息
    async getList () {
      var params = {
        // Id: this.insuranceId,
        SecurityType: 1, // 参保类型（1社会保险、2公积金）
        EmployeeGUID: this.employeeId,
        CompanyGUID: this.companyId
      }
      let res = await SysWelfarePercentEmployeeConfigApi.getList(params)
      if (res.status === 200 && res.data.success) {
        this.tableListData = res.data.data
      } else {
        this.tableListData = []
      }
    },

    // 返回员工花名册列表
    goEmployeeBookList () {
      EBbase.goEmployeeBookList(this.$router, this.companyId, this.companyName)
    },

    // 返回员工管理
    goRoster () {
      EBbase.goRoster(this.$router)
    }
  }
}
